package com.wkw.sdemo.service;

import com.wkw.sdemo.domain.Person;
import com.wkw.sdemo.enums.ResultEnum;
import com.wkw.sdemo.exception.PersonException;
import com.wkw.sdemo.repository.PersonRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class PersonService {
    @Autowired
    private PersonRepository personRepository;

     public void getAge(Integer id) throws Exception {
         Person person = personRepository.findOne(id);
         Integer age = person.getAge();
         if(age<20){
             //返回 青少年
             throw new PersonException(ResultEnum.QSN);
         }else if(age>20&&age<40){
             //返回 青年
             throw new PersonException(ResultEnum.QN);
         }
         //如果年纪越大越贵  例如医生
         throw new PersonException(ResultEnum.WXR);
     }
}
